//Controller κρατησης. Κανει κρατηση σε ενα καταστημα
package Controllers;

import DAO.Reservation_Dao;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Reservation_Controller {

    public Reservation_Controller(Reservation_Dao reservation_Dao) {

    }

    public boolean validateReservation(String Name, String LastName, String PhoneNumber, String SeatsNumber, String dateString)
            throws IllegalArgumentException {
        boolean x;
        SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        String dtStr = dateString.trim();
        Date date = null;
        try {
            date = df.parse(dtStr);
        } catch (ParseException e) {
           // throw new IllegalArgumentException("Incorrect date format");
        }
        if (Calendar.getInstance().getTime().after(date)) {
            //throw new IllegalArgumentException("Date has already passed");
        }
        if (Name.isEmpty() || LastName.isEmpty() || PhoneNumber.isEmpty() || SeatsNumber.isEmpty()) {
            x = false;
        } else if (PhoneNumber.matches("[0-9]+") == false) {
            x = false;
        } else if (PhoneNumber.length() > 10 || PhoneNumber.length() < 10) {
            x = false;
        } else if (SeatsNumber.matches("[0-9]+") == false) {
            x = false;
        } else if (Integer.parseInt(SeatsNumber) > 10) {
            x = false;
        } else {
            DAO.Reservation_Dao y = new DAO.Reservation_Dao();
            y.makeReservation(Name, LastName, PhoneNumber, SeatsNumber, dateString);
            x = true;
        }
        return x;
    }
}
